package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PricingRule;
import com.ruoyi.system.service.IPricingRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计费规则Controller
 * 
 * @author ruoyi
 * @date 2025-06-27
 */
@RestController
@RequestMapping("/system/rule")
public class PricingRuleController extends BaseController
{
    @Autowired
    private IPricingRuleService pricingRuleService;

    /**
     * 查询计费规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PricingRule pricingRule)
    {
        startPage();
        List<PricingRule> list = pricingRuleService.selectPricingRuleList(pricingRule);
        return getDataTable(list);
    }

    /**
     * 导出计费规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "计费规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PricingRule pricingRule)
    {
        List<PricingRule> list = pricingRuleService.selectPricingRuleList(pricingRule);
        ExcelUtil<PricingRule> util = new ExcelUtil<PricingRule>(PricingRule.class);
        util.exportExcel(response, list, "计费规则数据");
    }

    /**
     * 获取计费规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{prId}")
    public AjaxResult getInfo(@PathVariable("prId") Long prId)
    {
        return success(pricingRuleService.selectPricingRuleByPrId(prId));
    }

    /**
     * 新增计费规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "计费规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PricingRule pricingRule)
    {
        return toAjax(pricingRuleService.insertPricingRule(pricingRule));
    }

    /**
     * 修改计费规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "计费规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PricingRule pricingRule)
    {
        return toAjax(pricingRuleService.updatePricingRule(pricingRule));
    }

    /**
     * 删除计费规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "计费规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prIds}")
    public AjaxResult remove(@PathVariable Long[] prIds)
    {
        return toAjax(pricingRuleService.deletePricingRuleByPrIds(prIds));
    }
}
